import threading
import time

def s(t:int):
    print("sleep {} s begin".format(t))
    time.sleep(t)
    print("sleep {} s over".format(t))

def child():
    t = threading.Thread(target=s, args=(5,))
    t.setDaemon(True)
    t.start()
    s(2)

if __name__ == '__main__':
    # grand child's deamon thread is also main thread, not child thread
    
    t = threading.Thread(target=child)
    t.setDaemon(True)
    t.start()
    time.sleep(1)
    time.sleep(5)
    print("main over")
    exit()

    #if not set daemon, once main thread is killed, users need to wait for sub threads to over
    child()
    input("Press enter to exit...`")
    print("main over")

    
